<template>
    <div>
        <Modal v-model="modal" class="modal-full" title="导出模型" :width="800">
            <div class="json-editor" v-if="modalShow">
                <CodeEditor v-model="text" lang="json"></CodeEditor>
            </div>
            <div slot="footer" class="button-panel-button">
                <i-button @click="close">取消</i-button>
                <i-button @click="actionSubmit" type="primary">保存</i-button>
                <!---->
            </div>
        </Modal>
    </div>
</template>

<script>
import Base from '../modalBase'
import CodeEditor from '@/element/codeEditor'
import $ from '@/common'
export default {
    extends: Base,
    props: {
    },
    data() {
        return {
            text: null
            //使用所有者的model作为模型
        }
    },
    computed: {
    },
    watch: {
    },
    created() {
    },
    methods: {
        load() {
            var findPath = this.$parent.modelParam('path_find') || this.$parent.modelParam('path')
            if (findPath) {
                $.link(findPath, null, {
                    param: this.$parent.actionData
                }).then((res) => {
                    this.text = JSON.stringify(res.data, null, 2)
                })
            }
        },
        actionSubmit() {
            var data
            try {
                data = JSON.parse(this.text)
            } catch (ex) {
                this.$Notice.error({
                    title: 'JSON格式错误请检查'
                });
                console.warn(ex)
                return
            }
            $.link(this.modelParam('path_submit'), data,{
                param: this.$parent.actionData
            }).then(() => {
                this.$parent.actionSuccess('保存成功')
                this.close()
            })
        }
    },
    components: {
        CodeEditor
    }
}
</script>

<style lang="less">
.json-editor .CodeMirror {
    width: 100%;
    height: 100%;
}
</style>
